/******************************************************************************
**                                                                           **
**                 Proprietary and Confidential Information                  **
**                                                                           **
**                 Copyright (c) Conexant Systems, Inc. Unpublished                  **
**                                                                           **
** This source code and the algorithms implemented therein constitute        **
** confidential information and may compromise trade secrets of Conexant Systems,    **
** Inc. or its associates, and any unauthorized use thereof is prohibited.   **
**                                                                           **
******************************************************************************/
#ifndef _dc_image_api_h_
#define _dc_image_api_h_
/******************************************************************************
*  FILE FORMAT:
*      1. ENUMERATIONS
*      2. DEFINES
*      3. STRUCTURES
*      4. ALLOCS
*      5. FUNCTIONS
******************************************************************************/

/******************************************************************************
*  1. ENUMERATIONS
******************************************************************************/

/*
** DC_IMAGE_CHANNELS
**
** Defines the number of channels, and type of channels in the image.  The
** following is a key for channel types:
**   C = Cyan
**   M = Magenta
**   Y = Yellow
**   K = Black
**   Kt = Text Black
**   Kp = Photo Black
**   P = Protective (a.k.a. seal or transparent).
**   R = Red
**   G = Green
**   B = Blue
*/

#define DC_IMAGE_CHANNELS_CountBits 4
#define DC_IMAGE_CHANNELS_CountMask (0x0f)
#define DC_IMAGE_CHANNELS_nChannels(x) (x & DC_IMAGE_CHANNELS_CountMask)
#define DC_ChannelCountAndType(count, type) \
  (count | (type << DC_IMAGE_CHANNELS_CountBits))

typedef enum 
{ 

  DC_IMAGE_CHANNELS_UNKNOWN   = DC_ChannelCountAndType(0,0), //!< Unknown channel content

  DC_IMAGE_CHANNELS_1         = DC_ChannelCountAndType(1,0), //!< generic 1 channel
  DC_IMAGE_CHANNELS_K         = DC_ChannelCountAndType(1,1), //!< Use K channel
  DC_IMAGE_CHANNELS_Kt        = DC_ChannelCountAndType(1,2), //!< Use Kt channel
  DC_IMAGE_CHANNELS_C         = DC_ChannelCountAndType(1,3), //!< Use C channel
  DC_IMAGE_CHANNELS_M         = DC_ChannelCountAndType(1,4), //!< Use M channel
  DC_IMAGE_CHANNELS_Y         = DC_ChannelCountAndType(1,5), //!< Use Y channel
  DC_IMAGE_CHANNELS_L         = DC_ChannelCountAndType(1,6), //!< Use L channel

  DC_IMAGE_CHANNELS_2         = DC_ChannelCountAndType(2,0), //!< generic 2 channel
  DC_IMAGE_CHANNELS_CK        = DC_ChannelCountAndType(2,1), //!< for color/mono ink density maps
  DC_IMAGE_CHANNELS_KtKp      = DC_ChannelCountAndType(2,2), //!< Use KtKp channel
  DC_IMAGE_CHANNELS_KpP       = DC_ChannelCountAndType(2,3), //!< Use Kp, P channels

  DC_IMAGE_CHANNELS_3         = DC_ChannelCountAndType(3,0), //!< generic 3 channel
  DC_IMAGE_CHANNELS_RGB       = DC_ChannelCountAndType(3,1), //!< Use RGB channel
  DC_IMAGE_CHANNELS_YUV       = DC_ChannelCountAndType(3,2), //!< Use YUV channel
  DC_IMAGE_CHANNELS_YCrCb     = DC_ChannelCountAndType(3,2), //!< Use YCrCb channel
  DC_IMAGE_CHANNELS_LAB       = DC_ChannelCountAndType(3,3), //!< Use LAB channel
  DC_IMAGE_CHANNELS_CMY       = DC_ChannelCountAndType(3,4), //!< Use CMY channel

  DC_IMAGE_CHANNELS_4         = DC_ChannelCountAndType(4,0), //!< generic 4 channel
  DC_IMAGE_CHANNELS_CMYK      = DC_ChannelCountAndType(4,1), //!< Use CMYK channel
  DC_IMAGE_CHANNELS_CMYKt     = DC_ChannelCountAndType(4,2), //!< Use CMYKt channel
  DC_IMAGE_CHANNELS_CMYKp     = DC_ChannelCountAndType(4,3), //!< Use CMYKp channel
  DC_IMAGE_CHANNELS_xRGB      = DC_ChannelCountAndType(4,4), //!< Use xRGB channel
  DC_IMAGE_CHANNELS_BGRx      = DC_ChannelCountAndType(4,5), //!< Use BGRx channel

  DC_IMAGE_CHANNELS_5         = DC_ChannelCountAndType(5,0), //!< generic 5 channel
  DC_IMAGE_CHANNELS_CMYKpP    = DC_ChannelCountAndType(5,1), //!< Use CMYKpP channel
  DC_IMAGE_CHANNELS_CMYKtKp   = DC_ChannelCountAndType(5,2), //!< Use CMYKtKp channel

  DC_IMAGE_CHANNELS_6         = DC_ChannelCountAndType(6,0), //!< generic 5 channel
  DC_IMAGE_CHANNELS_CMYKcm    = DC_ChannelCountAndType(6,1), //!< Use CMYKcm channel
  DC_IMAGE_CHANNELS_CMYxcm    = DC_ChannelCountAndType(6,2), //!< Use CMYxcm channel (x is undefined)
  DC_IMAGE_CHANNELS_CMYKtKpP  = DC_ChannelCountAndType(6,3), //!< Use CMYKtKpP channel

  DC_IMAGE_CHANNELS_8         = DC_ChannelCountAndType(8,0), //!< generic 8 channel

  DC_IMAGE_CHANNELS_INVALID

} DC_IMAGE_CHANNELS;


#define DC_IMAGE_CHANNELS_FRIENDLY_LOOKUP_TABLE \
static struct DC_IMAGE_CHANNELS_FRIENDLY_LOOKUP_STRUCT { \
  DC_IMAGE_CHANNELS tag; \
  char string[9]; \
} dc_image_channels_friendly_lut[] = \
{ { DC_IMAGE_CHANNELS_UNKNOWN, "unknown", }, \
  { DC_IMAGE_CHANNELS_1, "1" }, \
  { DC_IMAGE_CHANNELS_K, "K" }, \
  { DC_IMAGE_CHANNELS_Kt, "Kt" }, \
  { DC_IMAGE_CHANNELS_C, "C" }, \
  { DC_IMAGE_CHANNELS_M, "M" }, \
  { DC_IMAGE_CHANNELS_Y, "Y" }, \
  { DC_IMAGE_CHANNELS_L, "L" }, \
  { DC_IMAGE_CHANNELS_2, "2" }, \
  { DC_IMAGE_CHANNELS_CK, "CK" }, \
  { DC_IMAGE_CHANNELS_KtKp, "KtKp" }, \
  { DC_IMAGE_CHANNELS_KpP, "KtP" }, \
  { DC_IMAGE_CHANNELS_3, "3" }, \
  { DC_IMAGE_CHANNELS_RGB, "RGB" }, \
  { DC_IMAGE_CHANNELS_YUV, "YUV" }, \
  { DC_IMAGE_CHANNELS_YCrCb, "YCrCb" }, \
  { DC_IMAGE_CHANNELS_LAB, "LAB" }, \
  { DC_IMAGE_CHANNELS_CMY, "CMY" }, \
  { DC_IMAGE_CHANNELS_4, "4" }, \
  { DC_IMAGE_CHANNELS_CMYK, "CMYK" }, \
  { DC_IMAGE_CHANNELS_CMYKt, "CMYKt" }, \
  { DC_IMAGE_CHANNELS_CMYKp, "CMYKp" }, \
  { DC_IMAGE_CHANNELS_xRGB, "xRGB" }, \
  { DC_IMAGE_CHANNELS_BGRx, "BGRx" }, \
  { DC_IMAGE_CHANNELS_5, "5" }, \
  { DC_IMAGE_CHANNELS_CMYKpP, "CMYKpP" }, \
  { DC_IMAGE_CHANNELS_CMYKtKp, "CMYKtKp" }, \
  { DC_IMAGE_CHANNELS_6, "6" }, \
  { DC_IMAGE_CHANNELS_CMYKcm, "CMYKcm" }, \
  { DC_IMAGE_CHANNELS_CMYxcm, "CMYxcm" }, \
  { DC_IMAGE_CHANNELS_CMYKtKpP, "CMYKtKpP" }, \
  { DC_IMAGE_CHANNELS_8, "8" }, \
  { DC_IMAGE_CHANNELS_INVALID, "invalid" } };

#define DC_IMAGE_CHANNELS_FRIENDLY_LOOKUP_FUNCTION \
char *dc_image_channels_friendly_lookup(DC_IMAGE_CHANNELS channels) \
{ \
  int i; \
  for(i=0;i<sizeof(dc_image_channels_friendly_lut)/sizeof(dc_image_channels_friendly_lut[0]);i++) { \
    if(channels == dc_image_channels_friendly_lut[i].tag) \
      return dc_image_channels_friendly_lut[i].string; \
  } \
  return dc_image_channels_friendly_lut[i-1].string; \
}

char *dc_image_channels_friendly_lookup(DC_IMAGE_CHANNELS channels);


/*
** DC_IMAGE_BITDEPTH
**
** Defines the bit depth of each channel of the image.
*/

typedef enum 
{
  DC_IMAGE_BITDEPTH_1 = 1, //!< Bit depth is 1
  DC_IMAGE_BITDEPTH_2 = 2, //!< Bit depth is 2
  DC_IMAGE_BITDEPTH_3 = 3, //!< Bit depth is 3
  DC_IMAGE_BITDEPTH_4 = 4, //!< Bit depth is 4
  DC_IMAGE_BITDEPTH_5 = 5, //!< Bit depth is 5
  DC_IMAGE_BITDEPTH_6 = 6, //!< Bit depth is 6
  DC_IMAGE_BITDEPTH_7 = 7, //!< Bit depth is 7
  DC_IMAGE_BITDEPTH_8 = 8, //!< Bit depth is 8
  DC_IMAGE_BITDEPTH_16 = 16, //!< Bit depth is 16
  DC_IMAGE_BITDEPTH_565,     //!< Bit depth is 565, 16
  DC_IMAGE_BITDEPTH_UNKNOWN, //!< Unknown bit depth
  DC_IMAGE_BITDEPTH_INVALID
} DC_IMAGE_BITDEPTH;   

#define DC_IMAGE_BITDEPTH_FRIENDLY_LOOKUP_TABLE \
static struct DC_IMAGE_BITDEPTH_FRIENDLY_LOOKUP_STRUCT { \
  DC_IMAGE_BITDEPTH tag; \
  char string[9]; \
} dc_image_bitdepth_friendly_lut[] = \
{ { DC_IMAGE_BITDEPTH_1, "1" }, \
  { DC_IMAGE_BITDEPTH_2, "2" }, \
  { DC_IMAGE_BITDEPTH_3, "3" }, \
  { DC_IMAGE_BITDEPTH_4, "4" }, \
  { DC_IMAGE_BITDEPTH_5, "5" }, \
  { DC_IMAGE_BITDEPTH_6, "6" }, \
  { DC_IMAGE_BITDEPTH_7, "7" }, \
  { DC_IMAGE_BITDEPTH_8, "8" }, \
  { DC_IMAGE_BITDEPTH_16, "16" }, \
  { DC_IMAGE_BITDEPTH_565, "565" }, \
  { DC_IMAGE_BITDEPTH_UNKNOWN, "unknown" }, \
  { DC_IMAGE_BITDEPTH_INVALID, "invalid" } };

#define DC_IMAGE_BITDEPTH_FRIENDLY_LOOKUP_FUNCTION \
char *dc_image_bitdepth_friendly_lookup(DC_IMAGE_BITDEPTH bitdepth) \
{ \
  int i; \
  for(i=0;i<sizeof(dc_image_bitdepth_friendly_lut)/sizeof(dc_image_bitdepth_friendly_lut[0]);i++) { \
    if(bitdepth == dc_image_bitdepth_friendly_lut[i].tag) \
      return dc_image_bitdepth_friendly_lut[i].string; \
  } \
  return dc_image_bitdepth_friendly_lut[i-1].string; \
}

char *dc_image_bitdepth_friendly_lookup(DC_IMAGE_BITDEPTH bitdepth);


/* 
** DC_IMAGE_FORMAT
**
** Defines the format of the image.
*/

typedef enum 
{ 
  DC_IMAGE_FORMAT_SCANLINE_INTERLEAVED, //!< scanline interleaved raw format
  DC_IMAGE_FORMAT_PIXEL_INTERLEAVED, //!< pixel interleaved raw format
  DC_IMAGE_FORMAT_LLJ, //!< LLJ format
  DC_IMAGE_FORMAT_JBIG, //!< JBIG format
  DC_IMAGE_FORMAT_SIMPLE, //!< Simple format
  DC_IMAGE_FORMAT_JPEG, //!< JPEG format
  DC_IMAGE_FORMAT_TIFF, //!< TIFF format
  DC_IMAGE_FORMAT_EXTENT, //!< Extent Data format
  DC_IMAGE_FORMAT_UNSPECIFIED, //!<unspecified
  DC_IMAGE_FORMAT_MH,    //!<MH format
  DC_IMAGE_FORMAT_MR,    //!<MR format
  DC_IMAGE_FORMAT_MMR,    //!<MMR format
  DC_IMAGE_FORMAT_PLANE_INTERLEAVED, //!<plane interleaved raw format
  DC_IMAGE_FORMAT_GZIP, //!<GZIP compressed
  DC_IMAGE_FORMAT_INVALID
} DC_IMAGE_FORMAT;


#define DC_IMAGE_FORMAT_FRIENDLY_LOOKUP_TABLE \
static struct DC_IMAGE_FORMAT_FRIENDLY_LOOKUP_STRUCT { \
  DC_IMAGE_FORMAT tag; \
  char string[9]; \
} dc_image_format_friendly_lut[] = \
{ { DC_IMAGE_FORMAT_SCANLINE_INTERLEAVED, "RAW_SINT" }, \
  { DC_IMAGE_FORMAT_PIXEL_INTERLEAVED, "RAW_PINT" }, \
  { DC_IMAGE_FORMAT_LLJ, "LLJ" }, \
  { DC_IMAGE_FORMAT_JBIG, "JBIG" }, \
  { DC_IMAGE_FORMAT_SIMPLE, "SIMPLE" }, \
  { DC_IMAGE_FORMAT_JPEG, "JPEG" }, \
  { DC_IMAGE_FORMAT_TIFF, "TIFF" }, \
  { DC_IMAGE_FORMAT_EXTENT, "EXTENT" }, \
  { DC_IMAGE_FORMAT_UNSPECIFIED, "UNSPEC'D" }, \
  { DC_IMAGE_FORMAT_MH, "MH" }, \
  { DC_IMAGE_FORMAT_MR, "MR" }, \
  { DC_IMAGE_FORMAT_MMR, "MMR" }, \
  { DC_IMAGE_FORMAT_PLANE_INTERLEAVED, "RAW_CINT" }, \
  { DC_IMAGE_FORMAT_INVALID, "invalid" } };

#define DC_IMAGE_FORMAT_FRIENDLY_LOOKUP_FUNCTION \
char *dc_image_format_friendly_lookup(DC_IMAGE_FORMAT format) \
{ \
  int i; \
  for(i=0;i<sizeof(dc_image_format_friendly_lut)/sizeof(dc_image_format_friendly_lut[0]);i++) { \
    if(format == dc_image_format_friendly_lut[i].tag) \
      return dc_image_format_friendly_lut[i].string; \
  } \
  return dc_image_format_friendly_lut[i-1].string; \
}

char *dc_image_format_friendly_lookup(DC_IMAGE_FORMAT format);

/*
** DC_IMAGE_COLOR_SPACE
**
** Defines the color space of the image.
*/

typedef enum
{
  DC_IMAGE_COLOR_SPACE_MONO, //!< color space mono
  DC_IMAGE_COLOR_SPACE_SRGB, //!< color space sRGB
  DC_IMAGE_COLOR_SPACE_INVALID
} DC_IMAGE_COLOR_SPACE;


#define DC_IMAGE_COLOR_SPACE_FRIENDLY_LOOKUP_TABLE \
static struct DC_IMAGE_COLOR_SPACE_FRIENDLY_LOOKUP_STRUCT { \
	DC_IMAGE_COLOR_SPACE tag; \
  char string[9]; \
} dc_image_color_space_friendly_lut[] = \
{ { DC_IMAGE_COLOR_SPACE_MONO, "Mono" }, \
  { DC_IMAGE_COLOR_SPACE_SRGB, "sRGB" }, \
  { DC_IMAGE_COLOR_SPACE_INVALID, "invalid" } };

#define DC_IMAGE_COLOR_SPACE_FRIENDLY_LOOKUP_FUNCTION \
char *dc_image_color_space_friendly_lookup(DC_IMAGE_COLOR_SPACE color_space) \
{ \
  int i; \
  for(i=0;i<sizeof(dc_image_color_space_friendly_lut)/sizeof(dc_image_color_space_friendly_lut[0]);i++) { \
    if(color_space == dc_image_color_space_friendly_lut[i].tag) \
      return dc_image_color_space_friendly_lut[i].string; \
  } \
  return dc_image_color_space_friendly_lut[i-1].string; \
}

char *dc_image_color_space_friendly_lookup(DC_IMAGE_COLOR_SPACE color_space);

/******************************************************************************
*  2. DEFINES
******************************************************************************/

#define DC_IMAGE_VERSION 0

/******************************************************************************
*  3. STRUCTURES
******************************************************************************/


/*
** Stride conventions.
**
** When using a scanline interleaved raw format, the stride member is by 
** convention defined to be the address increment in bytes required to move 
** from one channel scanline to the next channel scanline.  For multi-
** channel images, the stride from one scanline to the next scanline of the
** same channel with be N * (DC_IMAGE member stride), where N is the number
** of channels in the image.
*/

typedef struct DC_IMAGE_STRUCT 
{
  DC_IMAGE_CHANNELS channels;
  DC_IMAGE_BITDEPTH bitdepth;
  DC_IMAGE_FORMAT format;
  UINT32 stride;
  UINT32 width;
  UINT32 height;
} DC_IMAGE;


/******************************************************************************
*  4. ALLOCS
******************************************************************************/
/******************************************************************************
*  5. FUNCTIONS
******************************************************************************/

#endif  /* _dc_image_api_h_ */
